import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state={
  number:1
}

const actions={

  increment({commit}){
    commit('inc')
  },

  decrement({commit,state}){
    if(state.number>0){
      commit('decr')
    }
  }
}

const mutations={

  inc(state){
    state.number++
  },
  decr(state){
    state.number--
  }
}

const getters={
  evenOrOdd(state){
    return state.number %2 ==0 ?'偶数':'奇数'
  }
}


export default new Vuex.Store({
  state,
  actions,
  mutations,
  getters
})
